import Pages from '../../../pages/pages.vue'
import FakeRecordConfig from '../fake-record-config/fake-record-config.vue'
import { showMsg, fakeRecords, setMenuType, fakeRemove } from '../../../../vuex/action'

export default {
  name: 'fake-records',
  data() {
    return {
      activityName: this.activityName,
      activityId: +this.activityId,
      pages: {
        start: 0,
        totalPages: 0,
        limit: 20
      },
      fakeList: [],
      showFakeAdd: false
    }
  },
  vuex: {
    getters: {
      activityId: state => state.activityStoreId,
      activityName: state => state.activityStoreName,
      fresh: state => state.customFakeListNeedFresh
    },
    actions: {
      xShowMsg: showMsg,
      xFakeRecords: fakeRecords,
      xSetMenuType: setMenuType,
      xFakeRemove: fakeRemove
    }
  },
  components: {
    'vue-pages': Pages,
    'vue-fake-record': FakeRecordConfig
  },
  methods: {
    getList({start=this.pages.start, limit=this.pages.limit, activityId=this.activityId}) {
      this.xFakeRecords({
        activityId: activityId,
        start: start,
        limit: limit
      })
        .then((data) => {
          this.fakeList = data.list
          this.pages.totalPages = Math.ceil(data.totalcount / limit)
        })
        .catch((res) => {
          this.xShowMsg({
            type: 'danger',
            content: res.error_msg
          })
        })
    },
    romoveFake(recordId) {
      this.xFakeRemove({
        id: +recordId
      })
        .then(() => {
        })
        .catch((res) => {
          this.xShowMsg({
            type: 'danger',
            content: res.error_msg
          })
        })
    }
  },
  ready() {
    this.xSetMenuType('activity')
    this.getList({})
  },
  watch: {
    fresh() {
      if (this.fresh) {
        this.getList({})
      }
    }
  }
}
